﻿using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace POS.Framework
{
    public class SpecialGridView
    {
        public static void DrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
        }

        public static void SetGridViewIndicatorWidth(int rowCount, DevExpress.XtraGrid.Views.Grid.GridView obj)
        {
            obj.IndicatorWidth = 24 + 9 * (rowCount.ToString().Length);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        public static bool IsSimpleButton(object sender)
        {
            DevExpress.XtraEditors.SimpleButton button = sender as DevExpress.XtraEditors.SimpleButton;
            if (button != null) return true;
            return false;
        }
        /// <summary>
        /// gridView绑定数据后自动调整各列宽度
        /// </summary>
        /// <param name="gvResult">需要自适应的GridControl</param>
        /// <param name="fileNames">其中不需要自适应的列的FileName</param>
        public static void AutoColumnsWidth(GridView gvResult, params string[] fileNames)
        {
            foreach (DevExpress.XtraGrid.Columns.GridColumn col in gvResult.Columns)
            {
                if (fileNames.Contains(col.FieldName)) continue;
                col.BestFit();
            }
        }

        public static bool PrintBill(string templetName, Hashtable hash, DataTable dgv)
        {
            string printTempletPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\PrintTemplet\";
            VBprinter.EasyReport easyr = new VBprinter.EasyReport();
            easyr.SetReportDataSource(dgv);
            easyr.SetReportFile(printTempletPath + templetName);
            easyr.SetReportVar(hash);
            return easyr.PrintReport(false, false, true, true);
        }
    }
}
